package com.emep.changzhi.analyse.http.information;


import com.emep.changzhi.analyse.entity.information.SysWarningRecord;
import com.emep.changzhi.analyse.entity.information.SysWarningRule;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.information.SysWaringRuleService;
import com.emep.changzhi.analyse.service.information.SysWarningRecordService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**

 * @Description: 报警记录信息控制器
 */
@RestController
@RequestMapping("syswarningrecord")
@Api(value="报警记录信息controller",tags={"报警记录信息"})
public class SysWarningRecordController {

    @Autowired
    private SysWarningRecordService service;


    /**
     * 新增 报警规则信息
     * @param payload
     * @return
     */
    @ApiOperation(value="新增 报警记录信息", notes="新增 报警记录信息")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warningRule", value = "报警规则id", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "receiver", value = "接收人id", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "warningInfo", value = "报警信息", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "sendRule", value = "发送规则id", required = true, dataType = "String",paramType="query")
    })
    @PostMapping(value = "add")
    public ResultBean<SysWarningRecord> add(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "warningRule");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return result.boolAdd(service.add(payload));
        }
        return  result;
    }


    /**
     * 查询所有 报警记录信息
     * @return
     */
    @ApiOperation(value="获取报警记录信息列表", notes="获取报警记录信息列表")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @GetMapping(value = "list")
    public ResultBean<List<SysWarningRecord>> list(){
        return new ResultBean<>(service.getList());
    }


    /**
     * 根据id 删除 报警记录信息
     * @param payload
     */
    @ApiOperation(value="删除 报警记录信息", notes="删除 报警记录信息")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParam(name = "id", value = " 报警记录信息id", required = true, dataType = "String",paramType = "query")
    @DeleteMapping(value = "/delete")
    public ResultBean<Boolean> delete(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "id");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return result.bool(service.delete(payload.get("id").toString()));
        }
        return result;
    }

}
